<?php

namespace App\Http\Middleware;

use App\Http\Resources\ChooseStoresCollection;
use App\Models\Store;
use Closure;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class StoreMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $storeToken = $request->get('store_token', '');
        if (! $store = Cache::get($storeToken)) {
            return response('请登录店铺', 510);
        }
        $request->offsetSet('store', json_decode($store, true));
        return $next($request);
    }
}
